$(function() {
    var taskTable = null;
    var opts = {
        targetId: "taskTable",
        templateId: "tabletask",
        settings: {
            url: DI.queryRegionTaskList,
            ajaxType: "json",
            sourceInterface: {
                INum: "total",
                IData: "rows"
            },
            paginationIndexName: {
                "peerpageRows": "pageLimit",
                "currentPage": "pageNo"
            }
        },
        customFuncs: {
            delTaskPop: function(taskNo) {
                mainCtrl.deltaskNo = taskNo;
                $("#popup_del").show();
            },
            selAllcheckbox: function() {
                var curCheckboxs = $("table tbody td input[type=checkbox]");
                for (var i = 0; i < curCheckboxs.length; i++) {
                    if ($(curCheckboxs[i]).attr("disabled") != "disabled") {
                        if ($("#checkTop")[0].checked) {
                            curCheckboxs[i].checked = true;
                        } else {
                            curCheckboxs[i].checked = false;
                        }
                    }
                }
            }
        }
    };
    taskTable = SwiftUI.swiftTable.getInstance(opts);

    var mainCtrl = avalon.define({
        $id: "mainController",
        taskTopic: "",
        startTime: "",
        endTime: "",
        deltaskNo: "",
        searchTask: function() {
            var searchParam = {
                "endTime": mainCtrl.endTime,
                "startTime": mainCtrl.startTime,
                "taskTopic": mainCtrl.taskTopic
            }
            taskTable.search(searchParam);
        },
        exportTask: function() {
            var taskNos = [];
            var curCheckboxs = $("table tbody td input[type=checkbox]");
            for (var i = 0; i < curCheckboxs.length; i++) {
                if (curCheckboxs[i].checked) {
                    taskNos.push($(curCheckboxs[i]).val());
                }
            }
            if (taskNos.length == 0) {
                PLATFORM.showTips("warning", "请先选择任务再进行导出");
                return;
            }
            var stringtaskNos = JSON.stringify(taskNos);
            window.location.href = DI.regionExportCompltInfo + "?taskNos=" + stringtaskNos;
        }
    });
    var popCtrl = avalon.define({
        $id: "popController",
    });

    PLATFORM.datepickerRange("#starttime", "#endtime");

    avalon.scan();
});

/*
 * 分配状态  过滤器
 * 0未分配,1已分配;
 */
avalon.filters.filterAssignStatus = function(str, args, args2) {
        var ret = "未分配";
        if (str == 0) {
            ret = "未分配"
        } else if (str == 2) {
            ret = "已分配";
        } else if (str == 1) {
            ret = "修改待分配";
        }
        return ret;
    }
    /*
     * 任务状态 过滤器
     * 0 未开始 ,1 进行中,2 已结束,3 已删除;
     */
avalon.filters.filterTaskStatus = function(str, args, args2) {
    var ret = "未开始";
    if (str == 0) {
        ret = "未开始"
    } else if (str == 1) {
        ret = "进行中";
    } else if (str == 2) {
        ret = "已结束";
    } else if (str == 3) {
        ret = "已删除";
    }
    return ret;
}
